<?php
include_once ("../Login/databaseconnection.php");
 $Congeniality=$_POST['Congeniality'];
 $New_Congeniality=$_POST['New_Congeniality'];
 $Function=$_POST['Function'];
 $New_Function=$_POST['New_Function'];
 $Ethinicity=$_POST['Ethinicity'];
 $New_Ethinicity=$_POST['New_Ethinicity'];
$Principal_Name=$_POST['Principal_Name'];
 $School_Id=$_POST['School_Id'];
   $Zone=$_POST['Zone'];
  $Division=$_POST['Division'];
$Province=$_POST['Province'];
  $District=$_POST['District'];
  $Census_Number=$_POST['Census_Number'];
   $Name=$_POST['Name'];
   $Status=$_POST['Status'];
 $Type=$_POST['Type'];
   $Grade_Range=$_POST['Grade_Range'];
  $Medium=$_POST['Medium'];
  $Female_Students=$_POST['Female_Students'];
   $Male_Students=$_POST['Male_Students'];
   $Tp_Number=$_POST['Tp_Number'];
 $Fax_Number=$_POST['Fax_Number'];
  $E_Mail=$_POST['E_Mail'];
  $Web_Address=$_POST['Web_Address'];
  $Address=$_POST['Address'];
 $Account_Number=$_POST['Account_Number'];
  $Special_Projects=$_POST['Special_Projects'];
  $S_Pro="";
   $S_Proje="";
 date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
	if($New_Congeniality!=""&&$Congeniality!="Select One")
	{
$_SESSION['error']="Please select or type the congenalit!";
	}
	else if($New_Function!=""&&$Function!="Select One")
	{
$_SESSION['error']="Please select or type the function!";
	}
	else if($New_Ethinicity!=""&&$Ethinicity!="Select One")
	{
$_SESSION['error']="Please select or type the ethinicity!";
	}
	else
	{
	if($New_Ethinicity!="")
	{
	$Ethinicity=$New_Ethinicity;
	}
	if($New_Congeniality!="")
	{
	$Congeniality=$New_Congeniality;
	}
	if($New_Function!="")
	{
	$Function=$New_Function;
	}
   if($Congeniality!="Select One"&&$Function!="Select One"&&$Ethinicity!="Select One"&&$School_Id!=""&&$Zone!=""&&$Division!=""&&$Province!=""&&$District!=""&&$Census_Number!=""&&$Name!=""&&$Status!=""&&$Type!=""&&$Grade_Range!=""&&$Medium!=""&&$Principal_Name!=""&&$Female_Students!=""&&$Male_Students!=""&&$Address!="")
	{
	for($i=0;$i<sizeof($Special_Projects);$i++)
  {
  if($i==0)
  {
   if($Special_Projects[$i]=="Others(P1.specify)")
  {
  $S_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $S_Pro="other_";
  $_SESSION['errorspo']="Please type the other special projects!";
  }
  else
  {
  $S_Pro="other_".$spe_other;
  }
  }
  else
  {
  $S_Pro=$Special_Projects[0];
  }
  }
   else
  {
    if($Special_Projects[$i]=="Others(P1.specify)")
  {
  $S_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $S_Pro=$S_Pro.",other_";
  $_SESSION['errorspo']="Please type the other special projects!";
  }
  else
  {
  $S_Pro=$S_Pro.",other_".$spe_other;
  }
  }
  else
  {
	$S_Pro=$S_Pro.",".$Special_Projects[$i];
	}
	}
	 }
	 if($S_Proje=="yes")
  {
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
	  if($spe_other!="")
  {
	 $sql=mysql_query("INSERT INTO school(Congeniality,Function,Ethinicity,Principal_Name,School_Id,Zone,Division,Province,District,Census_Number,Name,Status,Type,Grade_Range,Medium,Female_Students,Male_Students,Tp_Number,Fax_Number,E_Mail,Web_Address,Special_Projects,Address,Account_Number,Last_Updated_Date)VALUES('$Congeniality','$Function','$Ethinicity','$Principal_Name','$School_Id','$Zone','$Division','$Province','$District','$Census_Number','$Name','$Status','$Type','$Grade_Range','$Medium','$Female_Students','$Male_Students','$Tp_Number','$Fax_Number','$E_Mail','$Web_Address','$S_Pro','$Address','$Account_Number','$t_d')");
    if(mysql_affected_rows()!=0)
  {
  $_SESSION['succ']="succ";
$_SESSION['error']="This record is successfully registered!";
  }

  if(mysql_affected_rows()==0)
  {
$_SESSION['error']="Sorry unable to register this record!";
  }
}
}
else
{
$sql=mysql_query("INSERT INTO school(Congeniality,Function,Ethinicity,Principal_Name,School_Id,Zone,Division,Province,District,Census_Number,Name,Status,Type,Grade_Range,Medium,Female_Students,Male_Students,Tp_Number,Fax_Number,E_Mail,Web_Address,Special_Projects,Address,Account_Number,Last_Updated_Date)VALUES('$Congeniality','$Function','$Ethinicity','$Principal_Name','$School_Id','$Zone','$Division','$Province','$District','$Census_Number','$Name','$Status','$Type','$Grade_Range','$Medium','$Female_Students','$Male_Students','$Tp_Number','$Fax_Number','$E_Mail','$Web_Address','$S_Pro','$Address','$Account_Number','$t_d')");
    if(mysql_affected_rows()!=0)
  {
  $_SESSION['succ']="succ";
$_SESSION['error']="This record is successfully registered!";
  }

  if(mysql_affected_rows()==0)
  {
$_SESSION['error']="Sorry unable to register this record!";
  }
}
}
}
if($Congeniality=="Select One"||$Function=="Select One"||$Ethinicity=="Select One"||$School_Id==""||$Zone==""||$Division==""||$Province==""||$District==""||$Census_Number==""||$Name==""||$Status==""||$Type==""||$Grade_Range==""||$Medium==""||$Female_Students==""||$Male_Students==""||$Principal_Name==""||$Address=="")
	{
		
		$_SESSION['errorin']="Indexed details are required,Please fill all!";
	
	}
?>